using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using ClickNET.Imaging;

namespace ClickNET
{
    public class ImageProcessor
    {
        public void Regen(string file, string id)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(file);
            ImageResize o = new ImageResize();

            String FullPath = fi.DirectoryName; // Path to File (minus filename)
            String Name = fi.Name; // File Name
            string[] pathArr = new string[32];

            // get just the parent directory out of FullPath
            char[] splitter = { '\\' };
            pathArr = FullPath.Split(splitter);
            string Directory = pathArr[pathArr.Length - 1];

            // Check to see if file is a jpg or something else
            if (Name.EndsWith("jpg", true, null) || Name.EndsWith("jpeg", true, null))
            {
                // Don't try to regen our freshly created thumbs
                if (!Directory.Contains("thumbs") && !Directory.EndsWith("galleries", true, null))
                {
                    Picture p = new Picture(file, Directory);
                    p.CreateThumbnails();
                }
                else
                {
                    Log.DefaultLog.WriteLine(fi.Name + " - Error. File is already a thumbnail");
                }
            }
            else
            {
                Log.DefaultLog.WriteLine(fi.Name + " - Error. File does not have a valid extension.");
            }
        }
    }
}
